New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

filelist-utils

Package Overview
Dependencies
Maintainers
0
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

filelist-utils

Create a FileCollection from a path or a zip file

1.11.3
latest
Source
npm
Version published
Weekly downloads
1.3K
-36.57%
Maintainers
0
Weekly downloads
 
Created
Source

filelist-utils

NPM version build status Test coverage npm download

Create a FileCollection from various sources.

Introduction

In order to make compatible code between the browser and node and to allow drag and drop of a folder it is useful to an abstraction level.

This package allows to create a FileCollection from various sources:

  • a FileList (that implements an Iterator of File).
  • a relative path (with its basedir)
  • a webservice that returns a JSON containing an array of object that has the following properties: relativePath, name, lastModified, size

A FileCollection has an iterator on FileCollectionItem that has the following properties:

  • lastModified: number;
  • name: string;
  • relativePath: string;
  • size: number;
  • arrayBuffer(): Promise;
  • stream(): ReadableStream;
  • text(): Promise;

Load and Save from remote server

// You should have a webservice that returns this kind of object

const source = {
  files: [
    {
      name: 'data.zip',
      size: 1589,
      relativePath: 'dataUnzip/data.zip',
      lastModified: 1664430693588,
    },
    {
      name: 'a.txt',
      size: 1,
      relativePath: 'dataUnzip/dir1/a.txt',
      lastModified: 1664430693588,
    },
  ],
  baseURL: 'http://localhost/',
};
const fileCollection = fileCollectionFromSource(source);

Installation

npm i filelist-utils

Usage

import { fileCollectionFromPath } from 'filelist-utils';

const fileCollection = fileCollectionFromPath(__dirname);
import { fileCollectionFromZip } from 'filelist-utils';

const zip = readFileSync(join(__dirname, 'test.zip'));
const fileCollection = fileCollectionFromZip(zip);

License

MIT

FAQs

Package last updated on 25 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts